<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>选择来款绑定流程</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">资金编号</div>
                    <div class="field">
                        <input name="code" id="code" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">来款账号</div>
                    <div class="field">
                        <input name="comeCode" id="comeCode" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">来款户名</div>
                    <div class="field">
                        <input name="comeName" id="comeName" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">来款金额</div>
                    <div class="field">
                        <input name="amount" id="amount" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var basePath = '<%=path%>';
    var grid = null, form = null;
    $(function () {
        form = $("#searchBar").ligerForm();

        grid = $("#ligergrid1").ligerGrid({
            url: basePath + '/capital/capFund/initList.do?type=${type}',
            method: 'get',
            parms: getSearchParams(),
            columns: [
                {
                    display: '资金编号', name: 'code', width: 130, align: 'left',
                    render: function (rowdata, index, value) {
                        return '<a href="javascript:;" style="cursor: pointer;" onclick="qyFund(' + rowdata.id + ')">' + rowdata.code + '</a>';
                    }
                },
                {display: '收款名称', name: 'acceptName', minWidth: 100, align: 'left',},
                {display: '收款账号', name: 'acceptCode', minWidth: 80, align: 'left',},
                {display: '到账日期', name: 'acceptDate', width: 100, align: 'center', render: renderDate},
                {display: '客户名称', name: 'cstNm', width: 90, align: 'left',},
                {display: '来款账号', name: 'comeCode', minWidth: 80, align: 'left',},
                {display: '来款户名', name: 'comeName', width: 100, align: 'left',},
                {
                    display: '来款金额', name: 'amount', width: 90, align: 'right',
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.amount / 100);
                    }
                },
                {
                    display: '可用金额', name: 'availableAmount', width: 90, align: 'right',
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.availableAmount / 100);
                    }
                },
                {display: '创建日期', name: 'crtTm', width: 130, align: 'center', render: renderDate2},
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: 20,
            fixedCellHeight: false,
            rownumbers: false,
            allowUnSelectRow: true,
            checkbox: true,
        });
        grid.setHeight(100);

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        //查询参数
        function getSearchParams() {
            var data = form.getData();
            return data;
        }

        frameElement.dialog.onOk = function () {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            frameElement.dialog.disabledBtns();
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push(selectedRows[index].id);
            }
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {ids: JSON.stringify(_ids), relationPayId:${relationPayId}},
                url: basePath + '/capital/capFund/flow/splitFund.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({
                        content: LogUtils.LOG_CMM_DATA_LOADING,
                        SQ_type: "waitting"
                    });
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: "资金关联成功", SQ_type: "success"});
                        if ("${bizTypCd}" === "1") {
                            parent.fundGrid.reload();
                        } else if ("${bizTypCd}" === "2") {
                            //父页面刷新
                            parent.location.reload();
                        }
                        frameElement.dialog.close();
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_showButtons: true, SQ_type: "error"});
                        frameElement.dialog.close();
                    }
                }
            });
        };
        frameElement.dialog.onCancel = function () {
            frameElement.dialog.hide();
        };

    });

    //查询资金信息
    function qyFund(_id) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 800,
            //height: 300,
            autoFixHeight: true,
            title: '资金信息',
            url: basePath + "/capital/capFund/toFundDtlPage.do?id=" + _id,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //格式化时间
    function renderDate2(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

</script>

</body>
</html>
